package com.xfsg.core.log.listener;

import com.xfsg.core.log.LogEnhancerBinder;
import com.xfsg.core.log.config.AliyunLogItem;
import com.xfsg.core.log.config.AliyunLogProperties;
import com.xfsg.core.log.enhancer.LogEnhancer;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.endpoint.event.RefreshEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;

/**
 * @author ZhangYi
 * @version 1.0.0
 * @Description:
 * @date 2022/1/10
 */
@Slf4j
@AllArgsConstructor
public class ConfigRefreshEventListener {

	private final AliyunLogProperties properties;
	private final AliyunLogItem logItem;

	@Order()
	@EventListener(RefreshEvent.class)
	public void afterConfigRefresh(RefreshEvent event) {
		LogEnhancer logEnhancer = LogEnhancerBinder.getInstance();
		logEnhancer.enhance(properties,logItem);
		log.info("config refresh finish");
	}
}
